package com.hp.service;

import com.hp.dao.FormMapper;
import com.hp.pojo.Form;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class FormService {

    @Autowired
    FormMapper formMapper;

    public Map<String, Object> getAllForms() {
        HashMap<String,Object> map=new HashMap<>();
        map.put("forms",formMapper.GetForms());

        return map;
    }

    public Map<String, Object> AddForm(Form form){
        Map<String,Object> map = new HashMap<>();
        try{
            formMapper.AddForm(form);
            map.put("message","添加成功");
            return map;
        }catch (Exception e){
            map.put("message","添加失败");
            e.printStackTrace();
            return map;
        }
    }

    public Map<String, Object> CompleteForm(int formId) {
        Map<String, Object> map = new HashMap<>();
        formMapper.CompleteForm(formId);
        map.put("message", "订单已完成");
        return map;
    }

//    public Map<String, Object> getFromsByagentId(int agentId) {
//        HashMap<String, Object> map=new HashMap<>();
//        map.put("forms",formMapper.GetFormsByagentId(agentId));
//
//        return map;
//    }

    public Map<String, Object> addForm(int houseId, int formType, int formBuyerid, int formSellerid, int agentId){
        Form form = new Form();
        form.setHouseId(houseId);
        form.setFormType(formType);
        form.setFormBuyerid(formBuyerid);
        form.setFormSellerid(formSellerid);
        form.setFormState(0);
        form.setFormEvidence("证明材料齐全");
        form.setAgentId(agentId);
        long time = new Date().getTime();
        form.setFormCreattime(time);
        formMapper.addForm(form);

        Map<String,Object> map = new HashMap<>();

        map.put("message", "success");

        return map;
    }
}
